function [c2_crit95,pval2]=find_crit_val(W_i,tau,order_V_Ln,h_w,k_type,T_n)

	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	% INITIALIZE
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

n=size(W_i,1);
N_sim=100000;
size_V_Ln=(order_V_Ln+1);

	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	% SET UP MATRIX V_Ln
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
V_Ln=NaN*ones(size_V_Ln,size_V_Ln);

Psi_int_analytic=NaN*ones(n,size_V_Ln);
parfor kk=1:size_V_Ln
	Psi_int_analytic(:,kk)=find_integral_analytic_1dim(W_i,h_w,k_type,kk);
end

Psi_int=Psi_int_analytic;

for kk=1:size_V_Ln
	for ll=1:size_V_Ln
		V_Ln(kk,ll)=tau*(1-tau)*(1/n)*Psi_int(:,kk)'*Psi_int(:,ll);
	end
end

	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	% FIND EIGENVALUES OF V_Ln
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
w_grid=linspace(min(W_i), max(W_i), 250)';
[lambda_hat_grid]=find_lambda_hat(W_i,w_grid,h_w,h_w,tau,k_type,order_V_Ln+1);

neig=size_V_Ln;
aux = randn(N_sim,neig);
cmat2 = randn(N_sim,neig);
cmat2 = cmat2.*cmat2;
tn2 = cmat2*lambda_hat_grid;

c2_crit95=percentiles(tn2,95);

pval2=mean(tn2>T_n);

	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	% END
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
